#pragma once
//
//  thread_allocator.hpp
//  JanMalloc
//
//  Created by janhit on 2022/4/16.
//

#ifndef thread_allocator_hpp
#define thread_allocator_hpp
#include <thread>
#include <map>
#include "../Concurrency/SpinLock.hpp"
#include "./TypesDef.hpp"

namespace MMFAlloc{

struct Allocator;

class ThreadAllocator
{

    friend class MemoryPool;
private:
    
    std::thread::id mTheadId;
    MMF::SpinLock mLock;
    std::map<u32, Allocator*> mAllocators;
    
public:
    
    ThreadAllocator(const std::thread::id& thdId);
    ~ThreadAllocator();
    
    void* Alloc(u32 size);
    void Free(void* addr);
    void Sharink();
};


}

#endif /* thread_allocator_hpp */
